import en from "@/mock/en.json"
import es from "@/mock/es.json"
import zhHans from "@/mock/zh-Hans.json"

let i18nConfig = {
  locale: "",
  messages: {
    en,
    es,
    "zh-Hans":zhHans
  }
};

import { createI18n } from "vue-i18n";

const i18n = createI18n(i18nConfig);
import Fly from "flyio/dist/npm/wx";
const fly = new Fly();

/**
 * 请求后台接口获取语言包
 * @param type
 * @returns {Promise}
 */
async function getLang(lang) {
  uni.setLocale(lang);
  i18n.global.locale = lang;
  return false
  let base = lang == "zh-Hans" ? "ch" : "en";
  await fly
    .get(`http://rap2api.taobao.org/app/mock/236414/aili/${base}`)
    .then((response) => {
      console.log("getLang", lang, response.data);
      i18n.global.setLocaleMessage(lang, response.data);
      i18n.global.locale = lang;
      uni.setLocale(lang);
    });
}

export { i18n, getLang };
